//
//  VideoListViewController.m
//  meiyaya
//
//  Created by 张领瑞 on 2017/9/12.
//  Copyright © 2017年 ShiFeiEr. All rights reserved.
//

#import "VideoListViewController.h"

@interface VideoListViewController ()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>

@property (nonatomic,strong)UICollectionView *collectionView;
@property (nonatomic,strong)NSMutableArray *dataSourceArray;
@end

@implementation VideoListViewController
#pragma mark 懒加载
-(NSMutableArray *)dataSourceArray{
    if (!_dataSourceArray) {
        _dataSourceArray = [[NSMutableArray alloc] init];
    }
    return _dataSourceArray;
}
-(UICollectionView *)collectionView{
    if (!_collectionView) {
        UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
        _collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, 0, 0) collectionViewLayout:layout];
        _collectionView.backgroundColor = [UIColor whiteColor];
        _collectionView.dataSource = self;
        _collectionView.delegate = self;
        _collectionView.showsVerticalScrollIndicator = NO;//隐藏滑杆
    }
    return _collectionView;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    //隐藏自带返回按钮
    self.navigationItem.hidesBackButton = YES;
    //重写返回按钮
    UIImage *retureImage = [[UIImage imageNamed:@"return"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithImage:retureImage style:UIBarButtonItemStylePlain target:self action:@selector(retureToCollegeViewController)];
    self.navigationItem.leftBarButtonItem = backItem;
    //设置title
    switch (self.showVideo) {
        case VideoShowAliving:
            self.title = @"正在直播";
            break;
        case VideoShowHotReplay:
            self.title = @"精彩回放";
            break;
        default:
            break;
    }
    //添加collectionview
    [self.view addSubview:self.collectionView];
    
    [_collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view);
        make.left.equalTo(self.view);
        make.right.equalTo(self.view);
        make.bottom.equalTo(self.view);
    }];
    //注册单元格
    [ _collectionView registerNib:[UINib nibWithNibName:@"CollectionViewCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"CollectionViewCell"];
    [ _collectionView registerNib:[UINib nibWithNibName:@"HotReplayViewCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"HotReplayViewCell"];
    // Do any additional setup after loading the view.
}

#pragma mark UICollectionViewDataSource Method
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return 4;
    return self.dataSourceArray.count;
    
}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    UICollectionViewCell *cell;
    if (self.showVideo == VideoShowAliving) {
        CollectionViewCell *collectionCell = [collectionView dequeueReusableCellWithReuseIdentifier:@"CollectionViewCell" forIndexPath:indexPath];
        cell = collectionCell;
    }else if (self.showVideo == VideoShowHotReplay){
        HotReplayViewCell *replayCell = [collectionView dequeueReusableCellWithReuseIdentifier:@"HotReplayViewCell" forIndexPath:indexPath];
        cell = replayCell;
    }
    return cell;
}

#pragma mark UICollectionViewDelegateFlowLayout Method

-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
    return UIEdgeInsetsMake(10, 10, 10, 10);
}
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
    return ITEM_SIZE;
}

-(CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{
    return 10;
}
-(CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{
    return 10;
}
//重写返回按钮响应
-(void)retureToCollegeViewController{
    
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
